/*
C# bindings for the FMod event engine
Copyright (C) 2007 David Wallin

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/

using System;
using System.Text;
using System.Runtime.InteropServices;

namespace FMOD
{
	public class EVENT_VERSION
	{
		public const int		number = 0x00010610;
		public const string		dll = "C_Binder.dll";
	}
	
	/*
	[DEFINE]
	[
		[NAME]
		EVENT_INITFLAGS

		[DESCRIPTION]   
		Initialization flags.  Use them with EventSystem::init in the eventflags parameter to change various behaviour.

		[REMARKS]

		[PLATFORMS]
		Win32, Win64, Linux, Linux64, Macintosh, Xbox, Xbox360, PlayStation 2, GameCube, PlayStation Portable, PlayStation 3

		[SEE_ALSO]
		EventSystem::init
	]
	*/
	public enum EVENT_INITFLAG
	{
		NORMAL = 0,
		USER_ASSETMANAGER = 1
	}
	/* [DEFINE_END] */
	
	
	
	/*
	[DEFINE]
	[
		[NAME] 
		EVENT_MODE

		[DESCRIPTION]   
		Event data loading bitfields. Bitwise OR them together for controlling how event data is loaded.

		[REMARKS]

		[PLATFORMS]
		Win32, Win64, Linux, Macintosh, Xbox, Xbox360, PlayStation 2, GameCube, PlayStation Portable, PlayStation 3, Wii

		[SEE_ALSO]
		EventGroup::loadEventData
		EventGroup::getEvent
		EventGroup::getEventByIndex
	]
	*/
	public enum EVENT_MODE
	{
		EVENT_DEFAULT = 0,
		EVENT_NONBLOCKING = 1,
		EVENT_ERROR_ON_DISKACCESS = 2,
		EVENT_INFOONLY = 4
	}
	/* [DEFINE_END] */
	
	
	
	/*
	[DEFINE]
	[
		[NAME] 
		EVENT_STATE

		[DESCRIPTION]   
		These values describe what state an event is in.

		[REMARKS]    
		The flags below can be combined to set multiple states at once.  Use bitwise AND operations to test for these.
		An example of a combined flag set would be EVENT_STATE_READY | EVENT_STATE_PLAYING.

		[PLATFORMS]
		Win32, Win64, Linux, Macintosh, Xbox, Xbox360, PlayStation 2, GameCube, PlayStation Portable, PlayStation 3, Wii

		[SEE_ALSO]
		Event::getState
		EVENT_MODE
	]
	*/
	public enum EVENT_STATE
	{
		EVENT_STATE_READY = 1,  /* Event is ready to play. */
		EVENT_STATE_LOADING = 2,  /* Loading in progress. */
		EVENT_STATE_ERROR = 4,  /* Failed to open - file not found, out of memory etc.  See return value of Event::getState for what happened. */
		EVENT_STATE_PLAYING = 8,  /* Event has been started.  This will still be true even if there are no sounds active.  Event::stop must be called or the event must stop itself using a 'one shot and stop event' parameter mode. */
		EVENT_STATE_CHANNELSACTIVE = 16,  /* Event has active voices.  Use this if you want to detect if sounds are playing in the event or not. */
		EVENT_STATE_INFOONLY = 32  /* Event was loaded with the EVENT_INFOONLY flag. */
	}
	/* [DEFINE_END] */
	
	
	
	/*
	[ENUM]
	[
		[DESCRIPTION]
		Property indices for Event::getPropertyByIndex.
        
		[REMARKS]        

		[PLATFORMS]
		Win32, Win64, Linux, Macintosh, Xbox, Xbox360, PlayStation 2, GameCube, PlayStation Portable, PlayStation 3, Wii

		[SEE_ALSO]
		Event::getPropertyByIndex
	]
	*/
	public enum EVENT_PROPERTY
	{
		EVENTPROPERTY_NAME = 0,              /* Type : char *    - Name of event. */
		EVENTPROPERTY_VOLUME,                /* Type : float     - Relative volume of event. */
		EVENTPROPERTY_PITCH,                 /* Type : float     - Relative pitch of event. */
		EVENTPROPERTY_PITCHRANDOMIZATION,    /* Type : float     - Random deviation in pitch of event. */
		EVENTPROPERTY_PRIORITY,              /* Type : int       - Playback priority of event. */
		EVENTPROPERTY_MAX_PLAYBACKS,         /* Type : int       - Maximum simultaneous playbacks of event. */
		EVENTPROPERTY_MAX_PLAYBACKS_BEHAVIOR,/* Type : int       - 0 = steal next, 1 = steal oldest, 2 = steal newest, 3 = steal quietest, 4 = just fail. */
		EVENTPROPERTY_MODE,                  /* Type : FMOD_MODE - Either FMOD_3D or FMOD_2D. */
		EVENTPROPERTY_3D_ROLLOFF,            /* Type : FMOD_MODE - Either FMOD_3D_LOGROLLOFF, FMOD_3D_LINEARROLLOFF, or none for custom rolloff.. */
		EVENTPROPERTY_3D_MINDISTANCE,        /* Type : float     - Minimum 3d distance of event. */
		EVENTPROPERTY_3D_MAXDISTANCE,        /* Type : float     - Maximum 3d distance of event.  Means different things depending on EVENTPROPERTY_3D_ROLLOFF. */
		EVENTPROPERTY_3D_POSITION,           /* Type : FMOD_MODE - Either FMOD_3D_HEADRELATIVE or FMOD_3D_WORLDRELATIVE. */
		EVENTPROPERTY_3D_CONEINSIDEANGLE,    /* Type : float     - Event cone inside angle.  0 to 360. */
		EVENTPROPERTY_3D_CONEOUTSIDEANGLE,   /* Type : float     - Event cone outside angle.  0 to 360. */
		EVENTPROPERTY_3D_CONEOUTSIDEVOLUME,  /* Type : float     - Event cone outside volume.  0 to 1.0. */
		EVENTPROPERTY_3D_DOPPLERSCALE,       /* Type : float     - Doppler scale where 0 = no doppler, 1.0 = normal doppler, 2.0 = double doppler etc. */
		EVENTPROPERTY_3D_SPEAKERSPREAD,      /* Type : float     - Angle of spread for stereo/mutlichannel source. 0 to 360. */
		EVENTPROPERTY_3D_PANLEVEL,           /* Type : float     - 0 = sound pans according to speaker levels, 1 = sound pans according to 3D position. */
		EVENTPROPERTY_SPEAKER_L,             /* Type : float     - 2D event volume for front left speaker. */
		EVENTPROPERTY_SPEAKER_C,             /* Type : float     - 2D event volume for front left speaker. */
		EVENTPROPERTY_SPEAKER_R,             /* Type : float     - 2D event volume for front left speaker. */
		EVENTPROPERTY_SPEAKER_LS,            /* Type : float     - 2D event volume for front left speaker. */
		EVENTPROPERTY_SPEAKER_RS,            /* Type : float     - 2D event volume for front left speaker. */
		EVENTPROPERTY_SPEAKER_LR,            /* Type : float     - 2D event volume for front left speaker. */
		EVENTPROPERTY_SPEAKER_RR,            /* Type : float     - 2D event volume for front left speaker. */
		EVENTPROPERTY_SPEAKER_LFE,           /* Type : float     - 2D event volume for front left speaker. */
		EVENTPROPERTY_REVERBLEVEL,           /* Type : float     - Reverb mix for this event where 0 = full reverb, -60 = no reverb. */
		EVENTPROPERTY_ONESHOT,               /* Type : int       - Oneshot event - stops when no channels playing */
		EVENTPROPERTY_FADEIN,                /* Type : int       - Time in milliseconds over which to fade this event in when programmer starts it. 0 = no fade in. */
		EVENTPROPERTY_FADEOUT,               /* Type : int       - Time in milliseconds over which to fade this event out when programmer stops it. 0 = no fade out. */
		EVENTPROPERTY_USER_BASE              /* User created events start from here onwards. */
	}
	
	
	/*
	[ENUM]
	[
		[DESCRIPTION]
		Flags to pass to EventGroup::loadEventData to determine what to load at the time of calling.
        
		[REMARKS]

		[PLATFORMS]
		Win32, Win64, Linux, Macintosh, Xbox, Xbox360, PlayStation 2, GameCube, PlayStation Portable, PlayStation 3, Wii

		[SEE_ALSO]
		EventGroup::loadEventData
	]
	*/
	public enum EVENT_RESOURCE
	{
		EVENT_RESOURCE_STREAMS_AND_SAMPLES,  /* Open all streams and load all banks into memory, under this group (recursive) */
		EVENT_RESOURCE_STREAMS,              /* Open all streams under this group (recursive).  No samples are loaded. */
		EVENT_RESOURCE_SAMPLES               /* Load all banks into memory, under this group (recursive).  No streams are opened. */
	}
	
	
	/*
	[ENUM]
	[
		[DESCRIPTION]   
		These callback types are used with EVENT_CALLBACK.

		[REMARKS]
		<b>Note!</b>  Currently the user must call EventSystem::update for these callbacks to trigger!
		<br>
		An EVENT_CALLBACKTYPE_SYNCPOINT callback is generated from 'markers' embedded in .wav files.
		These can be created by placing 'markers' in the original source wavs using a tool such as Sound Forge or Cooledit.<br>
		The wavs are then compiled into .FSB files when compiling the audio data using the FMOD designer tool.<br>
		Callbacks will be automatically generated at the correct place in the timeline when these markers are encountered
		which makes it useful for synchronization, lip syncing etc.<br>
		<br>
		An EVENT_CALLBACKTYPE_SOUNDDEF_START callback is generated each time a sound definition is played in an event.<br>
		This happens every time a sound definition starts due to the event parameter entering the region specified in the 
		layer created by the sound designer..<br>
		This also happens when sounds are randomly respawned using the random respawn feature in the sound definition 
		properties in FMOD designer.<br>
		<br>
		An EVENT_CALLBACKTYPE_SOUNDDEF_END callback is generated when a one-shot sound definition inside an event ends, 
		or when a looping sound definition stops due to the event parameter leaving the region specified in the layer created 
		by the sound designer.<br>
		<br>
		An EVENT_CALLBACKTYPE_NET_MODIFIED callback is generated when someone has connected to your running application with 
		FMOD Designer and changed a property within this event, for example volume or pitch.<br>

		[PLATFORMS]
		Win32, Win64, Linux, Macintosh, Xbox, Xbox360, PlayStation 2, GameCube, PlayStation Portable, PlayStation 3, Wii, Wii

		[SEE_ALSO]      
		Event::setCallback
		EVENT_CALLBACK
		EventSystem::update
	]
	*/
	public enum EVENT_CALLBACKTYPE
	{
		EVENT_CALLBACKTYPE_SYNCPOINT,        /* Called when a syncpoint is encountered.  Can be from wav file markers. */
		EVENT_CALLBACKTYPE_SOUNDDEF_START,   /* Called when a sound definition inside an event is triggered. */
		EVENT_CALLBACKTYPE_SOUNDDEF_END,     /* Called when a sound definition inside an event ends or is stopped. */
		EVENT_CALLBACKTYPE_STOLEN,           /* Called when an event runs out of instances and re-uses an existing event. */
		EVENT_CALLBACKTYPE_EVENTFINISHED,    /* Called when a non looping event parameter causes an event stop. */
		EVENT_CALLBACKTYPE_NET_MODIFIED,     /* Called when a property of the event has been modified by a network-connected host. */
		EVENT_CALLBACKTYPE_SOUNDDEF_CREATE,  /* Called when a programmer sound definition entry is loaded. */
		EVENT_CALLBACKTYPE_SOUNDDEF_RELEASE, /* Called when a programmer sound definition entry is unloaded. */
		EVENT_CALLBACKTYPE_SOUNDDEF_INFO     /* Called when a sound definition entry is loaded. */
	}
	
	
	/*
	[STRUCTURE]
	[
		[DESCRIPTION]
		Structure containing realtime information about a wavebank.

		[REMARKS]

		[PLATFORMS]
		Win32, Win64, Linux, Linux64, Macintosh, Xbox, Xbox360, PlayStation 2, GameCube, PlayStation Portable, PlayStation 3

		[SEE_ALSO]      
		EventSystem::getInfo
		EVENT_SYSTEMINFO
	]
	*/
	public struct EVENT_WAVEBANKINFO
	{
		public string name;                  /* [out] Name of this wave bank. */
		public int    streamrefcnt;          /* [out] Number of stream references to this wave bank made by events in this event system. */
		public int    samplerefcnt;          /* [out] Number of sample references to this wave bank made by events in this event system. */
		public int    numstreams;            /* [out] Number of times this wave bank has been opened for streaming. */
		public int    maxstreams;            /* [out] Maximum number of times this wave bank will be opened for streaming. */
		public int    streamsinuse;          /* [out] Number of streams currently in use. */
		public uint   streammemory;          /* [out] Amount of memory (in bytes) used by streams. */
		public uint   samplememory;          /* [out] Amount of memory (in bytes) used by samples. */
	}
	
	
	/*
	[STRUCTURE]
	[
		[DESCRIPTION]
		Structure containing realtime information about an event system.
		
		[REMARKS]
		
		[PLATFORMS]
		Win32, Win64, Linux, Linux64, Macintosh, Xbox, Xbox360, PlayStation 2, GameCube, PlayStation Portable, PlayStation 3
		
		[SEE_ALSO]      
		EventSystem::getInfo
		EVENT_WAVEBANKINFO
	]
	*/
	public struct EVENT_SYSTEMINFO
	{
		public int                  numevents;        /* [out] Total number of events in all event groups in this event system. */
		public int                  eventmemory;      /* [out] Amount of memory (in bytes) used by event hierarchy classes. */
		public int                  numinstances;     /* [out] Total number of event instances in all event groups in this event system. */
		public int                  instancememory;   /* [out] Amount of memory (in bytes) used by all event instances in this event system. */
		public int                  dspmemory;        /* [out] Amount of memory (in bytes) used by event dsp networks. */
		public int                  numwavebanks;     /* [out] Number of wave banks known to this event system. */
		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)]
		public EVENT_WAVEBANKINFO[] wavebankinfo;     /* [out] Array of detailed information on each wave bank. */
	}
	
	
	/*
	[STRUCTURE]
	[
		[DESCRIPTION]
		Structure containing extended information about an event.

		[REMARKS]
		This structure is optional!  Specify 0 or NULL in Event::getInfo if you don't need it!<br>

		[PLATFORMS]
		Win32, Win64, Linux, Linux64, Macintosh, Xbox, Xbox360, PlayStation 2, GameCube, PlayStation Portable, PlayStation 3

		[SEE_ALSO]      
		Event::getInfo
	]
	*/
	public struct EVENT_INFO
	{
		public int      memoryused;                   /* [out] Amount of memory (in bytes) used by this event. */
		public int      positionms;                   /* [out] Time passed in playback of this event instance in milliseconds. */
		public int      lengthms;                     /* [out] Length in milliseconds of this event. Note: lengthms will be -1 if the length of the event can't be determined i.e. if it has looping sounds. */
		public int      channelsplaying;              /* [out] Number of channels currently playing in this event instance. */
		public int      instancesactive;              /* [out] Number of event instances currently in use. */
		unsafe char**   wavebanknames;                /* [out] An array containing the names of all wave banks that are referenced by this event. */
		public uint     projectid;                    /* [out] The runtime 'EventProject' wide unique identifier for this event. */
		public uint     systemid;                     /* [out] The runtime 'EventSystem' wide unique identifier for this event.  This is calculated when single or multiple projects are loaded. */
	}
	
	
	/*
	[STRUCTURE]
	[
		[DESCRIPTION]
		Use this structure with EventSystem::load when more control is needed over loading.

		[REMARKS]
		This structure is optional!  Specify 0 or NULL in EventSystem::load if you don't need it!<br>
		<br>
		Members marked with [in] mean the user sets the value before passing it to the function.<br>
		Members marked with [out] mean FMOD sets the value to be used after the function exits.<br>
		Use sounddefentrylimit to limit the number of sound definition entries - and therefore the amount of wave data - loaded for each sound definition. This feature allows the programmer to implement a "low detail" setting at runtime without needing a seperate "low detail" set of assets.

		[PLATFORMS]
		Win32, Win64, Linux, Linux64, Macintosh, Xbox, Xbox360, PlayStation 2, GameCube, PlayStation Portable, PlayStation 3

		[SEE_ALSO]      
		EventSystem::load
	]
	*/
	public struct EVENT_LOADINFO
	{
		public uint size;
		public string encryptionkey;
		public float sounddefentrylimit;
	}
	
	/* 
		FMOD Callbacks
	*/
	public delegate RESULT EVENT_CALLBACK(IntPtr fmod_event, EVENT_CALLBACKTYPE type, IntPtr VOID_param1, IntPtr VOID_param2, IntPtr VOID_userdata);
	
	
	/*
		FMOD EventSystemSystem factory functions.  Use this to create an FMOD System Instance.  below you will see EventSystem_Init/Close to get started.
	*/
	public class EventSystem_Factory
	{
		public static RESULT EventSystem_Create(ref EventSystem system)
		{
			RESULT result = RESULT.OK;
			IntPtr raw = new IntPtr();
			EventSystem systemnew = null;
			
			result = FMOD_EventSystem_Create(ref raw);
			
			if(result != RESULT.OK)
			{
				return result;
			}
			
			systemnew = new EventSystem();
			systemnew.SetRaw(raw);
			system = systemnew;
			
			return result;
		}
		
		#region importfunctions
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_Create(ref IntPtr system);
		
		#endregion
	}
	
	public class EventSystem
	{
		public RESULT init(int maxchannels, INITFLAG flags, IntPtr VOID_extradriverdata, EVENT_INITFLAG eventflags)
		{
			return FMOD_EventSystem_Init(m_Raw, maxchannels, flags, VOID_extradriverdata, eventflags);
		}
		public RESULT release()
		{
			return FMOD_EventSystem_Release(m_Raw);
		}
		public RESULT update()
		{
			return FMOD_EventSystem_Update(m_Raw);
		}
		public RESULT setMediaPath(string path)
		{
			return FMOD_EventSystem_SetMediaPath(m_Raw, path);
		}
		public RESULT setPluginPath(string path)
		{
			return FMOD_EventSystem_SetPluginPath(m_Raw, path);
		}
		public RESULT getVersion(ref uint version)
		{
			return FMOD_EventSystem_GetVersion(m_Raw, ref version);
		}
		public RESULT getInfo(ref FMOD.EVENT_SYSTEMINFO info)
		{
			return FMOD_EventSystem_GetInfo(m_Raw, ref info);
		}
		public RESULT getSystemObject(ref FMOD.System f_system)
		{
			if(f_system == null)
			{
				f_system = new FMOD.System();
				IntPtr ptr = IntPtr.Zero;
				f_system.setRaw(ptr);
			}
			
			IntPtr s = f_system.getRaw();
			
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventSystem_GetSystemObject(m_Raw, ref s);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				f_system.setRaw(s);
			}
			
			return result;
		}
		
		public RESULT load(string filename, ref EVENT_LOADINFO loadinfo, ref EventProject project)
		{
			if(project == null)
			{
				project = new EventProject();
				IntPtr ptr = IntPtr.Zero;
				project.SetRaw(ptr);
			}
			
			IntPtr p = project.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventSystem_Load(m_Raw, filename, ref loadinfo, ref p);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				project.SetRaw(p);
			}
			
			return result;
		}
		public RESULT unload()
		{
			return FMOD_EventSystem_Unload(m_Raw);
		}
		
		public RESULT getProject(string name, ref EventProject project)
		{
			if(project == null)
			{
				project = new EventProject();
				IntPtr ptr = IntPtr.Zero;
				project.SetRaw(ptr);
			}
			
			IntPtr p = project.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventSystem_GetProject(m_Raw, name, ref p);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				project.SetRaw(p);
			}
			
			return result;
		}
		public RESULT getProjectByIndex(int index, ref EventProject project)
		{
			if(project == null)
			{
				project = new EventProject();
				IntPtr ptr = IntPtr.Zero;
				project.SetRaw(ptr);
			}
			
			IntPtr p = project.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventSystem_GetProjectByIndex(m_Raw, index, ref p);
			}
			catch(Exception)
			{
				result = RESULT.OK;
			}
			
			if(result == RESULT.OK)
			{
				project.SetRaw(p);
			}
			
			return result;
		}
		public RESULT getNumProjects(ref int numprojects)
		{
			return FMOD_EventSystem_GetNumProjects(m_Raw, ref numprojects);
		}
		public RESULT getCategory(string name, ref EventCategory category)
		{
			if(category == null)
			{
				category = new EventCategory();
				IntPtr ptr = IntPtr.Zero;
				category.SetRaw(ptr);
			}
			
			IntPtr c = category.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventSystem_GetCategory(m_Raw, name, ref c);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				category.SetRaw(c);
			}
			
			return result;
		}
		public RESULT getCategoryByIndex(int index, ref EventCategory category)
		{
			if(category == null)
			{
				category = new EventCategory();
				IntPtr ptr = IntPtr.Zero;
				category.SetRaw(ptr);
			}
			
			IntPtr c = category.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventSystem_GetCategoryByIndex(m_Raw, index, ref c);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				category.SetRaw(c);
			}
			
			return result;
		}
		public RESULT getNumCategories(ref int numcategories)
		{
			return FMOD_EventSystem_GetNumCategories(m_Raw, ref numcategories);
		}
		public RESULT getReverb(string name, ref EventReverb reverb)
		{
			if(reverb == null)
			{
				reverb = new EventReverb();
				IntPtr ptr = IntPtr.Zero;
				reverb.SetRaw(ptr);
			}
			
			IntPtr r = reverb.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventSystem_GetReverb(m_Raw, name, ref r);
			}
			catch(Exception)
			{
				result = RESULT.OK;
			}
			
			if(result == RESULT.OK)
			{
				reverb.SetRaw(r);
			}
			
			return result;
		}
		public RESULT getReverbByIndex(int index,  ref EventReverb reverb)
		{
			if(reverb == null)
			{
				reverb = new EventReverb();
				IntPtr ptr = IntPtr.Zero;
				reverb.SetRaw(ptr);
			}
			
			IntPtr r = reverb.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventSystem_GetReverbByIndex(m_Raw, index, ref r);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				reverb.SetRaw(r);
			}
			
			return result;
		}
		public RESULT getNumReverbs(ref int numreverbs)
		{
			return FMOD_EventSystem_GetNumReverbs(m_Raw, ref numreverbs);
		}
		
		public RESULT getGroup(string name, bool cacheevents, ref EventGroup group)
		{
			if(group == null)
			{
				group = new EventGroup();
				IntPtr ptr = IntPtr.Zero;
				group.SetRaw(ptr);
			}

			IntPtr g = group.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventSystem_GetGroup(m_Raw, name, cacheevents, ref g);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				group.SetRaw(g);
			}
			
			return result;
		}
		public RESULT getEvent(string name, EVENT_MODE mode, ref Event fmod_event)
		{
			if(fmod_event == null)
			{
				fmod_event = new Event();
				IntPtr ptr = IntPtr.Zero;
				fmod_event.SetRaw(ptr);
			}
			
			IntPtr e = fmod_event.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventSystem_GetEvent(m_Raw, name, mode, ref e);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				fmod_event.SetRaw(e);
			}
			
			return result;
		}
		public RESULT getEventBySystemID(uint systemid, EVENT_MODE mode, ref Event fmod_event)
		{
			if(fmod_event == null)
			{
				fmod_event = new Event();
				IntPtr ptr = IntPtr.Zero;
				fmod_event.SetRaw(ptr);
			}
			
			IntPtr e = fmod_event.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventSystem_GetEventBySystemID(m_Raw, systemid, mode, ref e);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				fmod_event.SetRaw(e);
			}
			
			return result;
		}
		public RESULT getNumEvents(ref int numevents)
		{
			return FMOD_EventSystem_GetNumEvents(m_Raw, ref numevents);
		}
		
		public RESULT set3DNumListeners(int numlisteners)
		{
			return FMOD_EventSystem_Set3DNumListeners(m_Raw, numlisteners);
		}
		public RESULT get3DNumListeners(ref int numlisteners)
		{
			return FMOD_EventSystem_Get3DNumListeners(m_Raw, ref numlisteners);
		}
		public RESULT set3DListenerAttributes(int listener, ref FMOD.VECTOR pos, ref FMOD.VECTOR vel, ref FMOD.VECTOR forward, ref FMOD.VECTOR up)
		{
			return FMOD_EventSystem_Set3DListenerAttributes(m_Raw, listener, ref pos, ref vel, ref forward, ref up);
		}
		public RESULT get3DListenerAttributes(int listener, ref FMOD.VECTOR pos, ref FMOD.VECTOR vel, ref FMOD.VECTOR forward, ref FMOD.VECTOR up)
		{
			return FMOD_EventSystem_Get3DListenerAttributes(m_Raw, listener, ref pos, ref vel, ref forward, ref up);
		}
		
		public RESULT registerMemoryFSB(string filename, IntPtr VOID_fsbdata, uint fsbdatalen)
		{
			return FMOD_EventSystem_RegisterMemoryFSB(m_Raw, filename, VOID_fsbdata, fsbdatalen);
		}
		public RESULT unregisterMemoryFSB(string filename)
		{
			return FMOD_EventSystem_UnregisterMemoryFSB(m_Raw, filename);
		}
		
		#region importfunctions
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_Init					  (IntPtr system, int maxchannels, INITFLAG flags, IntPtr VOID_extradriverdata, EVENT_INITFLAG eventflags);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_Release				  (IntPtr system);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_Update                  (IntPtr system);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_SetMediaPath            (IntPtr system, string path);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_SetPluginPath           (IntPtr system, string path);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetVersion              (IntPtr system, ref uint version);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetInfo                 (IntPtr system, ref FMOD.EVENT_SYSTEMINFO info);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetSystemObject         (IntPtr system, ref IntPtr f_system);
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_Load                    (IntPtr system, string filename, ref EVENT_LOADINFO loadinfo, ref IntPtr project);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_Unload                  (IntPtr system);
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetProject              (IntPtr system, string name, ref IntPtr project);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetProjectByIndex       (IntPtr system, int index, ref IntPtr project);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetNumProjects          (IntPtr system, ref int numprojects);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetCategory             (IntPtr system, string name, ref IntPtr category);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetCategoryByIndex      (IntPtr system, int index, ref IntPtr category);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetNumCategories        (IntPtr system, ref int numcategories);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetReverb               (IntPtr system, string name, ref IntPtr reverb);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetReverbByIndex        (IntPtr system, int index,  ref IntPtr reverb);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetNumReverbs           (IntPtr system, ref int numreverbs);
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetGroup                (IntPtr system, string name, bool cacheevents, ref IntPtr group);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetEvent                (IntPtr system, string name, EVENT_MODE mode, ref IntPtr fmod_event);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetEventBySystemID      (IntPtr system, uint systemid, EVENT_MODE mode, ref IntPtr fmod_event);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_GetNumEvents            (IntPtr system, ref int numevents);
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_Set3DNumListeners       (IntPtr system, int numlisteners);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_Get3DNumListeners       (IntPtr system, ref int numlisteners);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_Set3DListenerAttributes (IntPtr system, int listener, ref FMOD.VECTOR pos, ref FMOD.VECTOR vel, ref FMOD.VECTOR forward, ref FMOD.VECTOR up);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_Get3DListenerAttributes (IntPtr system, int listener, ref FMOD.VECTOR pos, ref FMOD.VECTOR vel, ref FMOD.VECTOR forward, ref FMOD.VECTOR up);
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_RegisterMemoryFSB       (IntPtr system, string filename, IntPtr VOID_fsbdata, uint fsbdatalen);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventSystem_UnregisterMemoryFSB     (IntPtr system, string filename);
		
		#endregion
		
		#region internalwrapper
		
		private IntPtr		m_Raw;
		
		public void SetRaw(IntPtr system)
		{
			m_Raw = new IntPtr();
			m_Raw = system;
		}
		
		public IntPtr GetRaw()
		{
			return m_Raw;
		}
		
		#endregion
	}

	public class EventProject
	{
		public RESULT release                ()
		{
			return FMOD_EventProject_Release(m_Raw);
		}
		public RESULT getInfo                (ref int index, ref string name)
		{
			return FMOD_EventProject_GetInfo(m_Raw, ref index, ref name);
		}
		public RESULT getGroup               (string name,		 bool cacheevents, ref EventGroup group)
		{
			if(group == null)
			{
				group = new EventGroup();
				IntPtr ptr = IntPtr.Zero;
				group.SetRaw(ptr);
			}
			
			IntPtr g = group.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventProject_GetGroup(m_Raw, name, cacheevents, ref g);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				group.SetRaw(g);
			}
			
			return result;
		}
		public RESULT getGroupByIndex        (int index,        bool cacheevents, ref EventGroup group)
		{
			if(group == null)
			{
				group = new EventGroup();
				IntPtr ptr = IntPtr.Zero;
				group.SetRaw(ptr);
			}
			
			IntPtr g = group.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventProject_GetGroupByIndex(m_Raw, index, cacheevents, ref g);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				group.SetRaw(g);
			}
			
			return result;
		}
		public RESULT getNumGroups           (ref int numgroups)
		{
			return FMOD_EventProject_GetNumGroups(m_Raw, ref numgroups);
		}
		public RESULT getEvent               (string name, EVENT_MODE mode, ref Event fmod_event)
		{
			if(fmod_event == null)
			{
				fmod_event = new Event();
				IntPtr ptr = IntPtr.Zero;
				fmod_event.SetRaw(ptr);
			}
			
			IntPtr e = fmod_event.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventProject_GetEvent(m_Raw, name, mode, ref e);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				fmod_event.SetRaw(e);
			}
			
			return result;
		}
		public RESULT getEventByProjectID    (uint projectid, EVENT_MODE mode, ref Event fmod_event)
		{
			if(fmod_event == null)
			{
				fmod_event = new Event();
				IntPtr ptr = IntPtr.Zero;
				fmod_event.SetRaw(ptr);
			}
			
			IntPtr e = fmod_event.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventProject_GetEventByProjectID(m_Raw, projectid, mode, ref e);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				fmod_event.SetRaw(e);
			}
			
			return result;
		}
		public RESULT getNumEvents           (ref int numevents)
		{
			return FMOD_EventProject_GetNumEvents(m_Raw, ref numevents);
		}
		
		#region importfunctions
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventProject_Release                (IntPtr project);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventProject_GetInfo                (IntPtr project, ref int index, ref string name);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventProject_GetGroup               (IntPtr project, string name,		 bool cacheevents, ref IntPtr group);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventProject_GetGroupByIndex        (IntPtr project, int index,        bool cacheevents, ref IntPtr group);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventProject_GetNumGroups           (IntPtr project, ref int numgroups);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventProject_GetEvent               (IntPtr project, string name, EVENT_MODE mode, ref IntPtr fmod_event);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventProject_GetEventByProjectID    (IntPtr project, uint projectid, EVENT_MODE mode, ref IntPtr fmod_event);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventProject_GetNumEvents           (IntPtr project, ref int numevents);
		
		#endregion
		
		#region internalwrapper
		
		private IntPtr		m_Raw;
		
		public void SetRaw(IntPtr parameter)
		{
			m_Raw = new IntPtr();
			m_Raw = parameter;
		}
		
		public IntPtr GetRaw()
		{
			return m_Raw;
		}
		
		#endregion
	}
	
	public class EventGroup
	{
		public RESULT getInfo                  (ref int index, ref string name)
		{
			return FMOD_EventGroup_GetInfo(m_Raw, ref index, ref name);
		}
		public RESULT loadEventData            (FMOD.EVENT_RESOURCE resource, EVENT_MODE mode)
		{
			return FMOD_EventGroup_LoadEventData(m_Raw, resource, mode);
		}
		public RESULT freeEventData                           (Event fmod_event)
		{
			return FMOD_EventGroup_FreeEventData(m_Raw, fmod_event.GetRaw());
		}
		public RESULT freeEventData                           ()
		{
			return FMOD_EventGroup_FreeEventData(m_Raw);
		}
		public RESULT getGroup                 (string name, bool cacheevents, ref EventGroup target_group)
		{
			if(target_group == null)
			{
				target_group = new EventGroup();
				IntPtr ptr = IntPtr.Zero;
				target_group.SetRaw(ptr);
			}
			
			IntPtr g = target_group.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventGroup_GetGroup(m_Raw, name, cacheevents, ref g);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				target_group.SetRaw(g);
			}
			
			return result;
		}
		public RESULT getGroupByIndex          (int index,   bool cacheevents, ref EventGroup target_group)
		{
			if(target_group == null)
			{
				target_group = new EventGroup();
				IntPtr ptr = IntPtr.Zero;
				target_group.SetRaw(ptr);
			}

			IntPtr g = target_group.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventGroup_GetGroupByIndex(m_Raw, index, cacheevents, ref g);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				target_group.SetRaw(g);
			}
			
			return result;
		}
		public RESULT getParentGroup           (ref EventGroup target_group)
		{
			if(target_group == null)
			{
				target_group = new EventGroup();
				IntPtr ptr = IntPtr.Zero;
				target_group.SetRaw(ptr);
			}
			
			IntPtr g = target_group.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventGroup_GetParentGroup(m_Raw, ref g);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				target_group.SetRaw(g);
			}
			
			return result;
		}
		public RESULT getParentProject         (ref EventProject project)
		{
			if(project == null)
			{
				project = new EventProject();
				IntPtr ptr = IntPtr.Zero;
				project.SetRaw(ptr);
			}
			
			IntPtr p = project.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventGroup_GetParentProject(m_Raw, ref p);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				project.SetRaw(p);
			}
			
			return result;
		}
		public RESULT getNumGroups             (ref int numgroups)
		{
			return FMOD_EventGroup_GetNumGroups(m_Raw, ref numgroups);
		}
		public RESULT getEvent                 (string name, EVENT_MODE mode, ref Event fmod_event)
		{
			if(fmod_event == null)
			{
				fmod_event = new Event();
				IntPtr ptr = IntPtr.Zero;
				fmod_event.SetRaw(ptr);
			}
			
			IntPtr e = fmod_event.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventGroup_GetEvent(m_Raw, name, mode, ref e);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				fmod_event.SetRaw(e);
			}
			
			return result;
		}
		public RESULT getEventByIndex          (int index,   EVENT_MODE mode, ref Event fmod_event)
		{
			if(fmod_event == null)
			{
				fmod_event = new Event();
				IntPtr ptr = IntPtr.Zero;
				fmod_event.SetRaw(ptr);
			}
			
			IntPtr e = fmod_event.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventGroup_GetEventByIndex(m_Raw, index, mode, ref e);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				fmod_event.SetRaw(e);
			}
			
			return result;
		}
		public RESULT getNumEvents             (ref int numevents)
		{
			return FMOD_EventGroup_GetNumEvents(m_Raw, ref numevents);
		}
		public RESULT getProperty              (string propertyname, IntPtr VOID_value)
		{
			return FMOD_EventGroup_GetProperty(m_Raw, propertyname, VOID_value);
		}
		public RESULT getPropertyByIndex       (int propertyindex, IntPtr VOID_value)
		{
			return FMOD_EventGroup_GetPropertyByIndex(m_Raw, propertyindex, VOID_value);
		}
		public RESULT getNumProperties         (ref int numproperties)
		{
			return FMOD_EventGroup_GetNumProperties(m_Raw, ref numproperties);
		}
		
		#region importfunctions
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventGroup_GetInfo                  (IntPtr group, ref int index, ref string name);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventGroup_LoadEventData            (IntPtr group, FMOD.EVENT_RESOURCE resource, EVENT_MODE mode);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventGroup_FreeEventData            (IntPtr group, IntPtr fmod_event);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventGroup_FreeEventData            (IntPtr group);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventGroup_GetGroup                 (IntPtr source_group, string name, bool cacheevents, ref IntPtr target_group);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventGroup_GetGroupByIndex          (IntPtr source_group, int index,   bool cacheevents, ref IntPtr target_group);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventGroup_GetParentGroup           (IntPtr source_group, ref IntPtr target_group);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventGroup_GetParentProject         (IntPtr group, ref IntPtr project);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventGroup_GetNumGroups             (IntPtr group, ref int numgroups);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventGroup_GetEvent                 (IntPtr group, string name, EVENT_MODE mode, ref IntPtr fmod_event);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventGroup_GetEventByIndex          (IntPtr group, int index,   EVENT_MODE mode, ref IntPtr fmod_event);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventGroup_GetNumEvents             (IntPtr group, ref int numevents);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventGroup_GetProperty              (IntPtr group, string propertyname, IntPtr VOID_value);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventGroup_GetPropertyByIndex       (IntPtr group, int propertyindex, IntPtr VOID_value);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventGroup_GetNumProperties         (IntPtr group, ref int numproperties);
		
		#endregion
		
		#region internalwrapper
		
		private IntPtr		m_Raw;
		
		public void SetRaw(IntPtr group)
		{
			m_Raw = new IntPtr();
			m_Raw = group;
		}
		
		public IntPtr GetRaw()
		{
			return m_Raw;
		}
		
		#endregion
	}
	
	public class EventCategory
	{
		public RESULT getInfo               (ref int index, ref string name)
		{
			return FMOD_EventCategory_GetInfo(m_Raw, ref index, ref name);
		}
		public RESULT getCategory           (string name, ref EventCategory target_category)
		{
			if(target_category == null)
			{
				target_category = new EventCategory();
				IntPtr ptr = IntPtr.Zero;
				target_category.SetRaw(ptr);
			}
			
			IntPtr c = target_category.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventCategory_GetCategory(m_Raw, name, ref c);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				target_category.SetRaw(c);
			}
			
			return result;
		}
		public RESULT getCategoryByIndex    (int index,   ref EventCategory target_category)
		{
			if(target_category == null)
			{
				target_category = new EventCategory();
				IntPtr ptr = IntPtr.Zero;
				target_category.SetRaw(ptr);
			}
			
			IntPtr c = target_category.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventCategory_GetCategoryByIndex(m_Raw, index, ref c);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				target_category.SetRaw(c);
			}
			
			return result;
		}
		public RESULT getNumCategories      (ref int numcategories)
		{
			return FMOD_EventCategory_GetNumCategories(m_Raw, ref numcategories);
		}
		
		public RESULT stopAllEvents         ()
		{
			return FMOD_EventCategory_StopAllEvents(m_Raw);
		}
		public RESULT setVolume             (float volume)
		{
			return FMOD_EventCategory_SetVolume(m_Raw, volume);
		}
		public RESULT getVolume             (ref float volume)
		{
			return FMOD_EventCategory_GetVolume(m_Raw, ref volume);
		}
		public RESULT setPitch              (float pitch)
		{
			return FMOD_EventCategory_SetPitch(m_Raw, pitch);
		}
		public RESULT getPitch              (ref float pitch)
		{
			return FMOD_EventCategory_GetPitch(m_Raw, ref pitch);
		}
		public RESULT setPaused             (bool paused)
		{
			return FMOD_EventCategory_SetPaused(m_Raw, paused);
		}
		public RESULT getPaused             (ref bool paused)
		{
			return FMOD_EventCategory_GetPaused(m_Raw, ref paused);
		}
		public RESULT setMute               (bool mute)
		{
			return FMOD_EventCategory_SetMute(m_Raw, mute);
		}
		public RESULT getMute               (ref bool mute)
		{
			return FMOD_EventCategory_GetMute(m_Raw, ref mute);
		}
		public RESULT getChannelGroup       (ref ChannelGroup channelgroup)
		{
			if(channelgroup == null)
			{
				channelgroup = new ChannelGroup();
				IntPtr ptr = IntPtr.Zero;
				channelgroup.setRaw(ptr);
			}
			
			IntPtr c = channelgroup.getRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_EventCategory_GetChannelGroup(m_Raw, ref c);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				channelgroup.setRaw(c);
			}
			
			return result;
		}
		
		#region importfunctions
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventCategory_GetInfo               (IntPtr category, ref int index, ref string name);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventCategory_GetCategory           (IntPtr source_category, string name, ref IntPtr target_category);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventCategory_GetCategoryByIndex    (IntPtr source_category, int index,   ref IntPtr target_category);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventCategory_GetNumCategories      (IntPtr category, ref int numcategories);
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventCategory_StopAllEvents         (IntPtr category);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventCategory_SetVolume             (IntPtr category, float volume);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventCategory_GetVolume             (IntPtr category, ref float volume);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventCategory_SetPitch              (IntPtr category, float pitch);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventCategory_GetPitch              (IntPtr category, ref float pitch);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventCategory_SetPaused             (IntPtr category, bool paused);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventCategory_GetPaused             (IntPtr category, ref bool paused);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventCategory_SetMute               (IntPtr category, bool mute);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventCategory_GetMute               (IntPtr category, ref bool mute);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventCategory_GetChannelGroup       (IntPtr category, ref IntPtr channelgroup);
		
		#endregion
		
		#region internalwrapper
		
		private IntPtr		m_Raw;
		
		public void SetRaw(IntPtr group)
		{
			m_Raw = new IntPtr();
			m_Raw = group;
		}
		
		public IntPtr GetRaw()
		{
			return m_Raw;
		}
		
		#endregion
	}
	
	public class Event
	{
		public RESULT start                         ()
		{
			return FMOD_Event_Start(m_Raw);
		}
		public RESULT stop                          ()
		{
			return FMOD_Event_Stop(m_Raw);
		}
		public RESULT stop                          (bool immediate)
		{
			return FMOD_Event_Stop(m_Raw, immediate);
		}
		
		public RESULT getInfo                       (ref int index, ref string name, ref EVENT_INFO info)
		{
			return FMOD_Event_GetInfo(m_Raw, ref index, ref name, ref info);
		}
		public RESULT getState                      (ref EVENT_STATE state)
		{
			return FMOD_Event_GetState(m_Raw, ref state);
		}
		public RESULT getParentGroup                (ref EventGroup group)
		{
			if(group == null)
			{
				group = new EventGroup();
				IntPtr ptr = IntPtr.Zero;
				group.SetRaw(ptr);
			}
			
			IntPtr g = group.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_Event_GetParentGroup(m_Raw, ref g);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				group.SetRaw(g);
			}
			
			return result;
		}
		public RESULT getChannelGroup               (ref ChannelGroup channelgroup)
		{
			if(channelgroup == null)
			{
				channelgroup = new ChannelGroup();
				IntPtr ptr = IntPtr.Zero;
				channelgroup.setRaw(ptr);
			}
			
			IntPtr c = channelgroup.getRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_Event_GetChannelGroup(m_Raw, ref c);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				channelgroup.setRaw(c);
			}
			
			return result;
		}
		public RESULT setCallback                   (EVENT_CALLBACK callback, IntPtr VOID_userdata)
		{
			return FMOD_Event_SetCallback(m_Raw, callback, VOID_userdata);
		}
		
		public RESULT getParameter                  (string name, ref EventParameter parameter)
		{
			if(parameter == null)
			{
				parameter = new EventParameter();
				IntPtr ptr = IntPtr.Zero;
				parameter.SetRaw(ptr);
			}
			
			IntPtr p = parameter.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_Event_GetParameter(m_Raw, name, ref p);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				parameter.SetRaw(p);
			}
			
			return result;
		}
		public RESULT getParameterByIndex           (int index, ref EventParameter parameter)
		{
			if(parameter == null)
			{
				parameter = new EventParameter();
				IntPtr ptr = IntPtr.Zero;
				parameter.SetRaw(ptr);
			}
			
			IntPtr p = parameter.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_Event_GetParameterByIndex(m_Raw, index, ref p);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				parameter.SetRaw(p);
			}
			
			return result;
		}
		public RESULT getNumParameters              (ref int numparameters)
		{
			return FMOD_Event_GetNumParameters(m_Raw, ref numparameters);
		}
		public RESULT getProperty                   (string propertyname, IntPtr VOID_value)
		{
			return FMOD_Event_GetProperty(m_Raw, propertyname, VOID_value);
		}
		public RESULT getPropertyByIndex            (int propertyindex,   IntPtr VOID_value)
		{
			return FMOD_Event_GetPropertyByIndex(m_Raw, propertyindex, VOID_value);
		}
		public RESULT getNumProperties              (ref int numproperties)
		{
			return FMOD_Event_GetNumProperties(m_Raw, ref numproperties);
		}
		public RESULT getCategory                   (ref EventCategory category)
		{
			if(category == null)
			{
				category = new EventCategory();
				IntPtr ptr = IntPtr.Zero;
				category.SetRaw(ptr);
			}
			
			IntPtr c = category.GetRaw();
			RESULT result = RESULT.OK;
			
			try
			{
				result = FMOD_Event_GetCategory(m_Raw, ref c);
			}
			catch(Exception)
			{
				result = RESULT.ERR_INVALID_PARAM;
			}
			
			if(result == RESULT.OK)
			{
				category.SetRaw(c);
			}
			
			return result;
		}
		
		public RESULT setVolume                     (float volume)
		{
			return FMOD_Event_SetVolume(m_Raw, volume);
		}
		public RESULT getVolume                     (ref float volume)
		{
			return FMOD_Event_GetVolume(m_Raw, ref volume);
		}
		public RESULT setPitch                      (float pitch)
		{
			return FMOD_Event_SetPitch(m_Raw, pitch);
		}
		public RESULT getPitch                      (ref float pitch)
		{
			return FMOD_Event_GetPitch(m_Raw, ref pitch);
		}
		public RESULT setPaused                     (bool paused)
		{
			return FMOD_Event_SetPaused(m_Raw, paused);
		}
		public RESULT getPaused                     (ref bool paused)
		{
			return FMOD_Event_GetPaused(m_Raw, ref paused);
		}
		public RESULT setMute                       (bool mute)
		{
			return FMOD_Event_SetMute(m_Raw, mute);
		}
		public RESULT getMute                       (ref bool mute)
		{
			return FMOD_Event_GetMute(m_Raw, ref mute);
		}
		public RESULT set3DAttributes               (ref FMOD.VECTOR position, ref FMOD.VECTOR velocity)
		{
			return FMOD_Event_Set3DAttributes(m_Raw, ref position, ref velocity);
		}
		public RESULT set3DAttributes               (ref FMOD.VECTOR position, ref FMOD.VECTOR velocity, ref FMOD.VECTOR orientation)
		{
			return FMOD_Event_Set3DAttributes(m_Raw, ref position, ref velocity, ref orientation);
		}
		public RESULT get3DAttributes               (ref FMOD.VECTOR position, ref FMOD.VECTOR velocity)
		{
			return FMOD_Event_Get3DAttributes(m_Raw, ref position, ref velocity);
		}
		public RESULT get3DAttributes               (ref FMOD.VECTOR position, ref FMOD.VECTOR velocity, ref FMOD.VECTOR orientation)
		{
			return FMOD_Event_Get3DAttributes(m_Raw, ref position, ref velocity, ref orientation);
		}
		public RESULT set3DOcclusion                (float directocclusion, float reverbocclusion)
		{
			return FMOD_Event_Set3DOcclusion(m_Raw, directocclusion, reverbocclusion);
		}
		public RESULT get3DOcclusion                (ref float directocclusion, ref float reverbocclusion)
		{
			return FMOD_Event_Get3DOcclusion(m_Raw, ref directocclusion, ref reverbocclusion);
		}
		public RESULT setReverbProperties           (ref REVERB_CHANNELPROPERTIES channelproperties)
		{
			return FMOD_Event_SetReverbProperties(m_Raw, ref channelproperties);
		}
		public RESULT getReverbProperties           (ref REVERB_CHANNELPROPERTIES prop)
		{
			return FMOD_Event_GetReverbProperties(m_Raw, ref prop);
		}
		
		#region importfunctions
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_Start                         (IntPtr fmod_event);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_Stop                          (IntPtr fmod_event, bool immediate);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_Stop                          (IntPtr fmod_event);
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetInfo                       (IntPtr fmod_event, ref int index, ref string name, ref EVENT_INFO info);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetState                      (IntPtr fmod_event, ref EVENT_STATE state);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetParentGroup                (IntPtr fmod_event, ref IntPtr group);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetChannelGroup               (IntPtr fmod_event, ref IntPtr channelgroup);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_SetCallback                   (IntPtr fmod_event, EVENT_CALLBACK callback, IntPtr VOID_userdata);
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetParameter                  (IntPtr fmod_event, string name, ref IntPtr parameter);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetParameterByIndex           (IntPtr fmod_event, int index, ref IntPtr parameter);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetNumParameters              (IntPtr fmod_event, ref int numparameters);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetProperty                   (IntPtr fmod_event, string propertyname, IntPtr VOID_value);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetPropertyByIndex            (IntPtr fmod_event, int propertyindex, IntPtr VOID_value);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetNumProperties              (IntPtr fmod_event, ref int numproperties);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetCategory                   (IntPtr fmod_event, ref IntPtr category);
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_SetVolume                     (IntPtr fmod_event, float volume);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetVolume                     (IntPtr fmod_event, ref float volume);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_SetPitch                      (IntPtr fmod_event, float pitch);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetPitch                      (IntPtr fmod_event, ref float pitch);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_SetPaused                     (IntPtr fmod_event, bool paused);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetPaused                     (IntPtr fmod_event, ref bool paused);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_SetMute                       (IntPtr fmod_event, bool mute);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetMute                       (IntPtr fmod_event, ref bool mute);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_Set3DAttributes               (IntPtr fmod_event, ref FMOD.VECTOR position, ref FMOD.VECTOR velocity);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_Set3DAttributes               (IntPtr fmod_event, ref FMOD.VECTOR position, ref FMOD.VECTOR velocity, ref FMOD.VECTOR orientation);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_Get3DAttributes               (IntPtr fmod_event, ref FMOD.VECTOR position, ref FMOD.VECTOR velocity);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_Get3DAttributes               (IntPtr fmod_event, ref FMOD.VECTOR position, ref FMOD.VECTOR velocity, ref FMOD.VECTOR orientation);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_Set3DOcclusion                (IntPtr fmod_event, float directocclusion, float reverbocclusion);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_Get3DOcclusion                (IntPtr fmod_event, ref float directocclusion, ref float reverbocclusion);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_SetReverbProperties           (IntPtr fmod_event, ref REVERB_CHANNELPROPERTIES channelproperties);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_Event_GetReverbProperties           (IntPtr fmod_event, ref REVERB_CHANNELPROPERTIES prop);
		
		#endregion
		
		#region internalwrapper
		
		private IntPtr		m_Raw;
		
		public void SetRaw(IntPtr fmod_event)
		{
			m_Raw = new IntPtr();
			m_Raw = fmod_event;
		}
		
		public IntPtr GetRaw()
		{
			return m_Raw;
		}
		
		#endregion
	}
	
	public class EventParameter
	{
		public RESULT getInfo              (ref int index, ref string name)
		{
			return FMOD_EventParameter_GetInfo(m_Raw, ref index, ref name);
		}
		public RESULT getRange(ref float rangemin, ref float rangemax)
		{
			return FMOD_EventParameter_GetRange(m_Raw, ref rangemin, ref rangemax);
		}
		public RESULT setValue(float value)
		{
			return FMOD_EventParameter_SetValue(m_Raw, value);
		}
		public RESULT getValue             (ref float _value)
		{
			return FMOD_EventParameter_GetValue(m_Raw, ref _value);
		}
		public RESULT setVelocity          (float _value)
		{
			return FMOD_EventParameter_SetVelocity(m_Raw, _value);
		}
		public RESULT getVelocity          (ref float _value)
		{
			return FMOD_EventParameter_GetVelocity(m_Raw, ref _value);
		}
		public RESULT setSeekSpeed         (float _value)
		{
			return FMOD_EventParameter_SetSeekSpeed(m_Raw, _value);
		}
		public RESULT getSeekSpeed         (ref float _value)
		{
			return FMOD_EventParameter_GetSeekSpeed(m_Raw, ref _value);
		}
		public RESULT keyOff               ()
		{
			return FMOD_EventParameter_KeyOff(m_Raw);
		}
		
		#region importfunctions
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventParameter_GetInfo              (IntPtr parameter, ref int index, ref string name);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventParameter_GetRange             (IntPtr parameter, ref float rangemin, ref float rangemax);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventParameter_SetValue             (IntPtr parameter, float _value);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventParameter_GetValue             (IntPtr parameter, ref float _value);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventParameter_SetVelocity          (IntPtr parameter, float _value);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventParameter_GetVelocity          (IntPtr parameter, ref float _value);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventParameter_SetSeekSpeed         (IntPtr parameter, float _value);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventParameter_GetSeekSpeed         (IntPtr parameter, ref float _value);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventParameter_KeyOff               (IntPtr parameter);
		
		#endregion
		
		#region internalwrapper
		
		private IntPtr		m_Raw;
		
		public void SetRaw(IntPtr parameter)
		{
			m_Raw = new IntPtr();
			m_Raw = parameter;
		}
		
		public IntPtr GetRaw()
		{
			return m_Raw;
		}
		
		#endregion
	}
	
	public class EventReverb
	{
		public RESULT release                 ()
		{
			return FMOD_EventReverb_Release(m_Raw);
		}
		public RESULT setProperties           (ref REVERB_PROPERTIES props)
		{
			return FMOD_EventReverb_SetProperties(m_Raw, ref props);
		}
		public RESULT getProperties           (ref REVERB_PROPERTIES props)
		{
			return FMOD_EventReverb_GetProperties(m_Raw, ref props);
		}
		public RESULT setActive               (IntPtr reverb, bool active)
		{
			return FMOD_EventReverb_SetActive(m_Raw, active);
		}
		public RESULT getInfo                 (ref int index, ref string name)
		{
			return FMOD_EventReverb_GetInfo(m_Raw, ref index, ref name);
		}
		
		#region importfunctions
		
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventReverb_Release                 (IntPtr reverb);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventReverb_SetProperties           (IntPtr reverb, ref REVERB_PROPERTIES props);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventReverb_GetProperties           (IntPtr reverb, ref REVERB_PROPERTIES props);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventReverb_SetActive               (IntPtr reverb, bool active);
		[DllImport(EVENT_VERSION.dll)]
		private static extern RESULT FMOD_EventReverb_GetInfo                 (IntPtr reverb, ref int index, ref string name);
		
		#endregion
		
		#region internalwrapper
		
		private IntPtr		m_Raw;
		
		public void SetRaw(IntPtr group)
		{
			m_Raw = new IntPtr();
			m_Raw = group;
		}
		
		public IntPtr GetRaw()
		{
			return m_Raw;
		}
		
		#endregion
	}
}
